package com.garlicts.framework.binlog.sync.util;

public class NamingUtil {

	/**
	 *	下划线命名的字符串转成驼峰 
	 */
	public static String UnderlineToHump(String underlineStr) {
		
		StringBuilder stringBuilder = new StringBuilder();
		String[] split = underlineStr.split("_");
		
		for(int i=0; i<split.length; i++) {
			if(i == 0) {
				stringBuilder.append(split[i].toLowerCase());
			}else {
				stringBuilder.append(split[i].substring(0, 1).toUpperCase());
				stringBuilder.append(split[i].substring(1).toLowerCase());
			}
		}
		
		return stringBuilder.toString();
		
	}
	
	/**
	 *	驼峰命名的字符串转成下划线 
	 */
	public static String humpToUnderline(String humpStr) {
		
		StringBuilder stringBuilder = new StringBuilder();
		
		for(int i=0; i<humpStr.length(); i++) {
			
			if(Character.isUpperCase(humpStr.charAt(i))) {
				
				char lowerCaseChar = Character.toLowerCase(humpStr.charAt(i));
				stringBuilder.append("_").append(lowerCaseChar);
				
			}else {
				
				stringBuilder.append(humpStr.charAt(i));
				
			}
			
		}
		
		return stringBuilder.toString();
		
	}
	
	public static void main(String[] args) {
		
		String str = "hhhh_iii_jjj_kkk";
		System.out.println(UnderlineToHump(str));
		
		
		String str2 = "hhhIiiJjjKkk";
		System.out.println(humpToUnderline(str2));
		
	}
	
}
